Merge "ForeignAPIRepo: Fetch thumb error from foreign repo"
authorTheDJ <hartman.wiki@gmail.com>
Sun, 19 May 2013 13:20:17 +0000 (13:20 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sun, 19 May 2013 13:20:17 +0000 (13:20 +0000)
includes/filerepo/ForeignAPIRepo.php
includes/filerepo/file/ForeignAPIFile.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index 5cd6fc2..6b0bc3a 100644 (file)
@@ -143,7 +143,7 @@ class ForeignAPIRepo extends FileRepo {
         * @return string
         */
        function fetchImageQuery( $query ) {
-               global $wgMemc;
+               global $wgMemc, $wgLanguageCode;
 
                $query = array_merge( $query,
                        array(
@@ -151,6 +151,9 @@ class ForeignAPIRepo extends FileRepo {
                                'action' => 'query',
                                'redirects' => 'true'
                        ) );
+               if ( !isset( $query['uselang'] ) ) { // uselang is unset or null
+                       $query['uselang'] = $wgLanguageCode;
+               }
                if ( $this->mApiBase ) {
                        $url = wfAppendQuery( $this->mApiBase, $query );
                } else {
@@ -242,6 +245,40 @@ class ForeignAPIRepo extends FileRepo {
                }
        }
 
+       /**
+        * @param $name string
+        * @param $width int
+        * @param $height int
+        * @param $otherParams string
+        * @return bool|MediaTransformError
+        * @since 1.22
+        */
+       function getThumbError( $name, $width = -1, $height = -1, $otherParams = '', $lang = null ) {
+               $data = $this->fetchImageQuery( array(
+                       'titles' => 'File:' . $name,
+                       'iiprop' => 'url|timestamp',
+                       'iiurlwidth' => $width,
+                       'iiurlheight' => $height,
+                       'iiurlparam' => $otherParams,
+                       'prop' => 'imageinfo',
+                       'uselang' => $lang,
+               ) );
+               $info = $this->getImageInfo( $data );
+
+               if( $data && $info && isset( $info['thumberror'] ) ) {
+                       wfDebug( __METHOD__ . " got remote thumb error " . $info['thumberror'] . "\n" );
+                       return new MediaTransformError(
+                               'thumbnail_error_remote',
+                               $width,
+                               $height,
+                               $this->getDisplayName(),
+                               $info['thumberror'] // already parsed message from foreign repo
+                       );
+               } else {
+                       return false;
+               }
+       }
+
        /**
         * Return the imageurl from cache if possible
         *
index 61d321e..8829cd9 100644 (file)
@@ -119,12 +119,25 @@ class ForeignAPIFile extends File {
                // Note, the this->canRender() check above implies
                // that we have a handler, and it can do makeParamString.
                $otherParams = $this->handler->makeParamString( $params );
+               $width = isset( $params['width'] ) ? $params['width'] : -1;
+               $height = isset( $params['height'] ) ? $params['height'] : -1;
 
                $thumbUrl = $this->repo->getThumbUrlFromCache(
                        $this->getName(),
-                       isset( $params['width'] ) ? $params['width'] : -1,
-                       isset( $params['height'] ) ? $params['height'] : -1,
-                       $otherParams );
+                       $width,
+                       $height,
+                       $otherParams
+               );
+               if ( $thumbUrl === false ) {
+                       global $wgLang;
+                       return $this->repo->getThumbError(
+                               $this->getName(),
+                               $width,
+                               $height,
+                               $otherParams,
+                               $wgLang->getCode()
+                       );
+               }
                return $this->handler->getTransform( $this, 'bogus', $thumbUrl, $params );
        }
 
index 3fb49ce..5a57e09 100644 (file)
@@ -3516,6 +3516,8 @@ Please visit [//www.mediawiki.org/wiki/Localisation MediaWiki Localisation] and
 'thumbnail-more'           => 'Enlarge',
 'filemissing'              => 'File missing',
 'thumbnail_error'          => 'Error creating thumbnail: $1',
+'thumbnail_error_remote'   => 'Error message from $1:
+$2',
 'djvu_page_error'          => 'DjVu page out of range',
 'djvu_no_xml'              => 'Unable to fetch XML for DjVu file',
 'thumbnail-temp-create'    => 'Unable to create temporary thumbnail file',
index b8f1a12..4713481 100644 (file)
@@ -6079,6 +6079,9 @@ The reason $1 is one of the following messages:
 * {{msg-mw|Djvu page error}}
 * {{msg-mw|Svg-long-error}}
 * other custom string',
+'thumbnail_error_remote' => 'Message shown in a thumbnail frame when creation of the thumbnail fails. Parameters:
+* $1 - is the name of the shared repository, see {{msg-mw|shardupload}}
+* $2 - the reason, see {{msg-mw|thumbnail_error}}',
 'djvu_page_error' => 'Used as error message.
 
 See also:
index 876b03d..f620f94 100644 (file)
@@ -2447,6 +2447,7 @@ $wgMessageStructure = array(
                'thumbnail-more',
                'filemissing',
                'thumbnail_error',
+               'thumbnail_error_remote',
                'djvu_page_error',
                'djvu_no_xml',
                'thumbnail-temp-create',